<script>

import * as echarts from 'echarts';
// import $ from 'jquery'
export default {
  name: 'VisualizationFourteen',
  data() {
    return{

    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.$axios.get('/api/vis/data23', {}).then(res => {
        if (res.data.code === 20041) {
          let data1 = [];
          let data2 = [];
          let data3 = [];
          let data4 = [];
          for (let i = 0; i < res.data.data.length; i++) {
            data1.push(
                res.data.data[i].param1
            );
            data2.push(
                res.data.data[i].param2
            );
          }
          //
          this.$axios.get('/api/vis/data24', {}).then(res => {
            if (res.data.code === 20041) {
              for (let i = 0; i < res.data.data.length; i++) {
                data3.push(
                    res.data.data[i].param2
                );
              }
              //
              this.$axios.get('/api/vis/data25', {}).then(res => {
                if (res.data.code === 20041) {
                  for (let i = 0; i < res.data.data.length; i++) {
                    data4.push(
                        res.data.data[i].param2
                    );
                  }
                  this.init(data1, data2, data3,  data4);
                }
              }).catch(error => {
                this.open4(error);
              })
            }
          }).catch(error => {
            this.open4(error);
          })
        }
      }).catch(error => {
        this.open4(error);
      })
    },
    open4(msg) {
      this.$notify.error({
        title: msg,
        message: '这是一条错误的提示消息'
      });
    },
    init(data1, data2, data3,  data4) {
      var chartDom = document.getElementById('main14');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        legend: {
          data: ['100-350', '350-650', '650以上']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'value'
        },
        yAxis: {
          type: 'category',
          data: data1
        },
        series: [
          {
            name: '100-350',
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            z: 10,
            data: data2
          },
          {
            name: '350-650',
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            z: 10,
            data: data3
          },
          {
            name: '650以上',
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideRight'
              }
            },
            z: 10,
            data: data4
          }
        ]
      };
      option && myChart.setOption(option);
    }
  }

}
</script>

<template>
  <div id="main14"></div>
</template>

<style scoped>
#main14 {
  width: 100%;
  height: 100%;
}
</style>